<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-03 21:46:21
 * @LastEditTime: 2019-10-19 11:00:55
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div class="dongdan">
    <h3>
      <span>热门动弹</span>
    </h3>
    <div class="dongdan-input">
      <textarea placeholder="来吐槽一下吧！" style="width:70%" v-model="dongdan" v-if="!!id" />
      <textarea placeholder="来吐槽一下吧！" style="width:70%" v-model="dongdan" v-if="!!!id" disabled />
      <button class="dongdan-btn" style="width:20%" @click="sendDongdan">发送</button>
    </div>
    <div class="dongdan-tip">
      <a>Tip:多发动弹能发现很多有趣的东西哦！</a>
    </div>
    <div class="dongdan-select">最新动弹</div>
    <transition-group name="list">
      <div class="dongdan-box" v-for="value in dongdanList" :key="value.id" :id="value.id">
        <div class="box-left">
          <img :src="value.userinfo.avatar" />
        </div>
        <div class="box-right">
          <span>
            <a v-if="value.userinfo">{{value.userinfo.nickname}}:</a>
            {{value.dongForm}}
          </span>
          <div class="ctl">
            <div class="ctl-text">{{$moment(value.createdAt).fromNow()}}</div>
            <div class="ctl-like">
              <!-- <Icon type="md-heart" size="14" />0 -->
              举报
            </div>
          </div>
        </div>
      </div>
    </transition-group>
  </div>
</template>
<script>
export default {
  name: "Dongdan",
  props: ["id"],
  data() {
    return {
      dongdanList: [],
      dongdan: ""
    };
  },
  created() {
    this.$axios.get(this.$store.getters.url + "/getDongdan").then(res => {
      this.dongdanList = res.data.data;
    });
  },
  mounted() {},
  methods: {
    //发送动弹
    sendDongdan: function() {
      if (this.dongdan !== "") {
        this.$axios
          .get(this.$store.getters.url + "/createDongdan", {
            params: {
              dongForm: this.dongdan,
              userId: this.id
            }
          })
          .then(res => {
            console.log(res.data);
            if (res.data.code == 200) {
              this.$Message.success(res.data.msg);
              let data = res.data.data;
              let user = res.data.user;
              Object.assign(data, {
                userinfo: { nickname: user.nickname, avatar: user.avatar }
              });
              console.log(data);
              this.dongdanList.unshift(data);
              this.dongdan = "";
            } else {
              this.$Message.info(res.data.msg);
            }
          });
      } else {
        this.$Message.info("输入不可为空！");
      }
      // this.dongdanList.unshift(this.dongdanList[0]);
    }
  }
};
</script>
<style lang="scss" scoped>
// $baseUrl:"../../../../../assets";
.dongdan {
  width: 100%;
  height: auto;
  padding-bottom: 30px;
  background-color: white;
  h3 {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 31px;
    span {
      border-bottom: 1px solid black;
    }
  }
}
.dongdan-input {
  display: flex;
  width: 100%;
  justify-content: center;
  padding-top: 10px;
  padding-bottom: 10px;
  textarea {
    font-size: 12px;
    padding: 8px;
    width: 236px;
    height: 51px;
    border: 1px solid #d8d8d8;
    border-right: none;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    resize: none;
    outline: 0;
    appearance: none;
    &::-webkit-scrollbar {
      display: none;
    }
  }
  button {
    width: 50px;
    outline: none;
    border: 0;
    background-color: #d8d8d8;
    color: white;
    font-weight: bold;
    cursor: pointer;
    &:hover {
      background-color: #7e7e7e;
    }
  }
}
.dongdan-tip {
  display: flex;
  padding-left: 20px;
  padding-bottom: 10px;
}
.dongdan-select {
  display: flex;
  padding-left: 20px;
}
.dongdan-box {
  display: flex;
  width: 100%;
  height: auto;
  align-items: flex-start;
  // animation: showBox 0.4s;
  .box-left {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    // background-image: url("../../../../assets/logo.png");
    background-size: contain;
    margin-left: 20px;
    margin-top: 10px;
    margin-right: 10px;
    img {
      width: 35px;
      height: 35px;
      border-radius: 50%;
      box-shadow: 0px 0px 5px black;
    }
  }
  .box-right {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-right: 20px;
    height: auto;
    margin-top: 10px;
    font-size: 14px;
    span {
      text-align: left;
    }
    .ctl {
      display: flex;
      width: 100%;
      height: 25px;
      justify-content: space-between;
      .ctl-text {
        font-size: 12px;
        color: #ccc;
        margin-top: 5px;
        cursor: pointer;
      }
      .ctl-like {
        display: flex;
        align-items: center;
        color: #ccc;
        margin-top: 5px;
        font-size: 12px;
        cursor: pointer;
      }
    }
  }
}
@mixin item($num) {
  $waitTime: ($num) * 0.2-0.2;
  transition: all 0.2s ease-in-out #{$waitTime}s;
}
@for $i from 1 through 10 {
  .list-enter-active:nth-child(#{$i}) {
    @include item($i);
  }
  .list-leave-active:nth-child(#{$i}) {
    @include item($i);
  }
}
// .list-enter-active,
// .list-leave-active {
//   transition: all 0.4s;
// }
.list-enter,
.list-leave-to {
  opacity: 0;
  transform: translateY(30px);
}
@keyframes showBox {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
</style>